package com.cpht.app.model;

import javax.persistence.*;
import java.util.Date;

/**
 * Copyright (C) 2007 Cape Henry Technologies Inc.
 * <p/>
 * This program is open software. It is licensed using the Apache Software
 * Foundation, version 2.0 January 2004
 * <p/>
 * <a href="mailto:dlwhitehurst@gmail.com">dlwhitehurst@gmail.com</a>
 *
 * generate artifacts mvn appfuse:gen -Dentity=Name
 *
 * @author David L. Whitehurst
 * @version 1.0
 */
@Entity
@Table(name="pet")
public class Pet extends BaseObject {

    /**
     * Primary key: Each Hibernate object will have a primary key or id.
     * All ids for this application will be a Long type.
     *
     */
    Long id;

    /**
     * Pet Name: This variable holds the pet name in a String variable.
     */
    String petName;

    /**
     * Genus (taxonomy): This String variable holds the genus for the pet.
     */
    String genus;

    /**
     * Species (taxonomy): This String variable holds the species for the pet.
     */
    String species;

    /**
     * Common name: the common name for the pet.
     */
    String commonName;

    /**
     * Birth Date: The pet's birthdate (maybe estimated)
     */
    Date birthDate;

    /**
     * Age: of pet in years.  If pet is less than a year old will be zero.
     */
    int age;

    /**
     * Getter for birth date member
     * @return
     */
    @Column
    public Date getBirthDate() {
        return birthDate;
    }

    /**
     * Setter for birth date member
     * @param birthDate
     */
    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    /**
     * Getter for id or primary key
     * @return
     */
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    /**
     * Setter for id or primary key
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Getter for pet name member
     * @return
     */
    @Column(nullable=false,length=50,unique=true)
    public String getPetName() {
        return petName;
    }

    /**
     * Setter for pet name member
     * @param petName
     */
    public void setPetName(String petName) {
        this.petName = petName;
    }

    /**
     * Getter for genus member
     * @return
     */
    @Column(length=50)
    public String getGenus() {
        return genus;
    }

    /**
     * Setter for genus member
     * @param genus
     */
    public void setGenus(String genus) {
        this.genus = genus;
    }

    /**
     * Getter for species member
     * @return
     */
    @Column(length=50)
    public String getSpecies() {
        return species;
    }

    /**
     * Setter for species member
     * @param species
     */
    public void setSpecies(String species) {
        this.species = species;
    }

    /**
     * Getter for common name member
     * @return
     */
    @Column(length=50)
    public String getCommonName() {
        return commonName;
    }

    /**
     * Setter for common name member
     * @param commonName
     */
    public void setCommonName(String commonName) {
        this.commonName = commonName;
    }

    /**
     * Getter for age member
     * @return
     */
    @Column
    public int getAge() {
        return age;
    }

    /**
     * Setter for age member
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }


    /**
     * Returns a multi-line String with key=value pairs.
     *
     * @return a String representation of this class.
     */
    public String toString() {
        return petName + ", the " + commonName;
    }

    /**
     * Compares object equality. When using Hibernate, the primary key should
     * not be a part of this comparison.
     *
     * @param o object to compare to
     * @return true/false based on equality tests
     */
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Pet)) {
            return false;
        }

        final Pet pet = (Pet) o;

        return !(petName != null ? !petName.equals(pet.getPetName()) : pet.getPetName() != null);
    }

    /**
     * When you override equals, you should override hashCode. See "Why are
     * equals() and hashCode() importation" for more information:
     * http://www.hibernate.org/109.html
     *
     * @return hashCode
     */
    public int hashCode() {
        return (petName != null ? petName.hashCode() : 0);
    }
}
